#!/usr/bin/env python
#coding:utf8
import MySQLdb

from flask import Flask,render_template,request
app = Flask(__name__)

@app.route('/login',methods=["POST","GET"])
def login():
    if request.method == "POST":

        phone= request.form["phone"]
        passwd= request.form["passwd"]

        conn = MySQLdb.connect(host="127.0.0.1",user="root",passwd="run2014LK",db="test",port=3306,charset="utf8")
        cur = conn.cursor()

        query = 'SELECT phone,passwd,status FROM user WHERE phone = "{phone}";'.format(phone=phone)
        if cur.execute(query):
            phone,dpasswd,status = cur.fetchone()
            
	    if status:
                if dpasswd == passwd:
                    return "登录成功"
                else:
                    return "密码错误"
            else:
                return "用户未激活"
        else:
            return "无此用户"
        return result.get("message","system error")
    return render_template("login.html")

if __name__ == '__main__':
    app.run(debug=True,host="0.0.0.0",port=9999)